package com.tvein.sanguo.action.controller.skill
{
	//flash
	//pureMVC
	import flash.display.DisplayObject;
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.action.view.ActionMediator;
	import com.tvein.sanguo.action.model.SystemProxy;
	import com.tvein.sanguo.swc.action.skill.Skill0;
	import com.tvein.sanguo.swc.action.skill.Skill1;
	import com.tvein.sanguo.swc.action.skill.Skill2;
//
	public class ActionSkill extends SimpleFabricationCommand implements ICommand
	{
		private var actionMediator:ActionMediator;
		private var systemData:SystemProxy;
		
		override public function execute(notification:INotification) : void
		{
			actionMediator = facade.retrieveMediator(ActionMediator.NAME) as ActionMediator;
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			clearChild();

			var params:Object = new Object();

			switch (notification.getBody().Main.id)
			{
				case 0:
					var actionSkill0:Skill0 = new Skill0();
					actionMediator.action.addChild(actionSkill0);
					actionSkill0.name = "Skill-0";
					
					params.Volume = systemData.effectVol;
					actionSkill0.console("setEffect", params);
					
					actionSkill0.console("setData", notification.getBody().Process);
					actionSkill0.addEventListener("Skill-0", actionMediator._handleEvents);

					break;
				case 1:
					var actionSkill1:Skill1 = new Skill1();
					actionMediator.action.addChild(actionSkill1);
					actionSkill1.name = "Skill-1";
					
					params.Volume = systemData.effectVol;
					actionSkill1.console("setEffect", params);
					params.TargetId = notification.getBody().Main.targetId;
					actionSkill1.console("setTargetId", params);
					
					actionSkill1.console("setData", notification.getBody().Process);
					actionSkill1.addEventListener("Skill-1", actionMediator._handleEvents);
					
					break;
				case 2:
					var actionSkill2:Skill2 = new Skill2();
					actionMediator.action.addChild(actionSkill2);
					actionSkill2.name = "Skill-2";
					
					params.Volume = systemData.effectVol;
					actionSkill2.console("setEffect", params);
					params.TargetId = notification.getBody().Main.targetId;
					actionSkill2.console("setTargetId", params);
					
					actionSkill2.console("setData", notification.getBody().Process);
					actionSkill2.addEventListener("Skill-2", actionMediator._handleEvents);
					
					break;
			}
		}
		
		private function clearChild():void
		{
			for (var i:int = actionMediator.action.numChildren - 1; i >= 0; i--)
			{
				actionMediator.action.removeChildAt(0); 
			}
		}
	}
}